<?php
/**
 * 轻云网络验证系统
 * =======================================================
 * 版权所有(C) 2019-2039 daenx.cn，并保留所有权利。
 * 作者：Daen大恩
 * 作者QQ: 1330166565
 * 开发群：661059773
 * =======================================================
 */
    include 'farmwork.php';
	header("content-type:text/html;charset=utf-8");
	login();
	include 'chushi.php';
	$sql = "SELECT * FROM `products` WHERE cp ='$ycp';";
	$result=mysqli_query($con,$sql);
	if($result&&mysqli_num_rows($result)){
	   while ($row=mysqli_fetch_assoc($result)) {
				$jg1 = $row['jg1'];
				$jg2 = $row['jg2'];
				$jg3 = $row['jg3'];
				$jg4 = $row['jg4'];
				$jg5 = $row['jg5'];
				$jg6 = $row['jg6'];
				$xjjg1 = $row['xjjg1'];
				$xjjg2 = $row['xjjg2'];
				$xjjg3 = $row['xjjg3'];
				$xjjg4 = $row['xjjg4'];
				$xjjg5 = $row['xjjg5'];
				$xjjg6 = $row['xjjg6'];
	   }
	}

	
	$uid = $_SESSION['user_uid'];
	$action = $_GET['action'];
	if($action=='do'){
		$jb = $_POST['jb'];
		if($jb=="无权限"){
			if($dl="超管"){
				echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">你是代理商，没有权限添加下级！</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'daili.php' });  }});</script>");
			}
		}
		if($jb=="代理商"){
			if($dl="授权商"){
				$xf = $xjjg1;
			}
			if($dl="总销商"){
				$xf = $xjjg3;
			}
			if($dl="超管"){
				$xf = $xjjg6;
			}
		}
		if($jb=="授权商"){
			if($dl="总销商"){
				$xf = $xjjg2;
			}
			if($dl="超管"){
				$xf = $xjjg5;
			}
		}
		if($jb=="总销商"){
			if($dl="超管"){
				$xf = $xjjg4;
			}
		}


		$zhekouhou = $xf;
		if($rmb<$zhekouhou){
		   echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">您的余额不足！<br>本次需要花费".$zhekouhou."元</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'daili.php' });  }});</script>");
		}else{
		$rmb = $rmb - $zhekouhou;
		$domain = $_POST['domain'];
		$qq = $_POST['qq'];
		$ycp = $_POST['ycp'];
		$pass = $_POST['pass'];
		$bz = $_POST['bz'];
		$time = time();
	

	    $sql="select * from daili where domain='$domain' and ycp='$ycp'";
        $query=mysqli_query($con,$sql);
        $rows = mysqli_num_rows($query);
		if($rows > 0){
		   echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">代理已存在！</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'daili-add.php' });  }});</script>");
		}else{
		   $sql = "INSERT INTO `daili` (`domain`,`pass`,`qq`,`time`,`yumi`,`ycp`,`rmb`,`dl`,`bz`,`num`,`up`) VALUES ('$domain','$pass','$qq','$time',0,'$ycp',0,'$jb','$bz',0,'$uid');";
		   mysqli_query($con,$sql);
		   $sql = "UPDATE `daili` SET `rmb` = '$rmb' where id='$uid'";
		   mysqli_query($con,$sql);
		    $ip = getip();
			$time1=time();
			$sql = "INSERT INTO `log_dl` (`uid`,`time`,`cp`,`rmb`,`zrmb`,`bz`,`ip`) VALUES ('$uid', '$time1', '$ycp', '-$zhekouhou', '$rmb', '添加授权','$ip');";//添加流水日志
			mysqli_query($con,$sql);
		
		   mysqli_close();
		   echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">添加成功！</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'daili.php' });  }});</script>");
		   die;
		}
	}}

$li66='class="active"';
$li661='class="active"';
?>
<?php include 'header.php';?>
    <title>添加代理-<?php echo $title?></title>
<?php include 'list.php';?>
    <!--main content start-->
    <section id="main-content">
        <section class="wrapper">
<?php include 'overview.php';?>
            <div class="row">
                <div class="col-lg-12">
                    <!--work progress start-->
                    <section class="panel">
                        <div class="panel-body progress-panel">
                            <div class="task-progress">
                                <h1>添加下级代理</h1>
                                <p>填写代理信息并保存.</p>
                            </div>
                        </div>
						<form action="daili-add.php?action=do" method="post"  role="form">
                            <div class="form-group">
                                <label for="txtDomain">产品</label>
                                <select name="ycp" class="form-control" >
								
 									<?php 
											echo "<option value='".$ycp."'>".$ycp."</option>";											
									?>   
									</select>
                            </div>					
                            <div class="form-group">
                                <label for="txtDomain">账号</label>
                                <input type="text" name="domain" class="form-control" placeholder="登录账号" autocomplete="off" required/>
                            </div>
                           <div class="form-group">
                                <label for="txtDomain">密码</label>
                                <input type="text" name="pass" class="form-control" placeholder="登录密码" autocomplete="off" required/>
                            </div>
                            <div class="form-group">
                                <label for="txtDomain">联系人QQ</label>
                                <input type="text" name="qq" class="form-control" placeholder="联系人QQ" autocomplete="off" required/>
                            </div>

							
                            <div class="form-group">
							  <label>级别</label>
							  <select name="jb" class="form-control">
							  
							  <?php
							  if($dl == "代理商"){
								  echo  "<option value='无权限'>无权限</option>";
							  }
							  if($dl == "授权商"){
								  echo  "<option value='代理商'>代理商：￥".$xjjg1."</option>";
							  }
							  if($dl == "总销商"){
								  echo  "<option value='代理商'>代理商：￥".$xjjg3."</option><option value='授权商'>授权商：￥".$xjjg2."</option>";
							  }
							  if($dl == "超管"){
								  echo  "<option value='代理商'>代理商：￥".$xjjg6."</option><option value='授权商'>授权商：￥".$xjjg5."</option><option value='总销商'>总销商：￥".$xjjg4."</option>";
							  }
							  
							  ?>

							  </select>
							</div>
							
			<div class="form-group">
				<label for="txtDomain">备注</label>
				<input type="text" name="bz" class="form-control" placeholder="备注"/>
			</div>
			<div id="bottom" >
			  <button class="btn btn-info" type="submit" value="true" id="submit"/><strong>添加授权</strong></button>
            </div>
                        </form>
                    </section>
                    <!--work progress end-->
                </div>

        </section>
    </section>
    <!--main content end-->

<?php include 'footer.php';?>
